<template>
  <div id="login">
    <login-nav-bar />
    <login-main
      :captcha-address="captchaAddress"
      @handleImgBarter="handleImgBarter"
      @handleVerificationCode="handleVerificationCode"
    />
  </div>
</template>

<script>
import LoginNavBar from "./childComps/LoginNavBar";
import LoginMain from "./childComps/LoginMain";

import { mapGetters } from "vuex";

import { getCaptchas, getLogin } from "network/login";
import { request7 } from "network/request";
export default {
  data() {
    return {
      captchaAddress: "", //验证码地址
      // tipMessage: '',//登录提示信息
    };
  },
  components: {
    LoginNavBar,
    LoginMain,
  },
  computed: {
    ...mapGetters(["geohash"]),
  },
  created() {
    this.getCaptchas();
    // request7()
  },

  methods: {
    // 验证码
    getCaptchas() {
      getCaptchas().then((res) => {
        this.captchaAddress = res.code;
      });
    },
    // 验证验证码的正确
    getLogin(username, password, captcha_code) {
      getLogin(username, password, captcha_code).then((res) => {
        if (res.message) {
          this.$toast.handleTipsText(res.message);
          this.getCaptchas();
        } else {
          this.$router.go(-1);
          localStorage.setItem('user_id',res.id)
          this.$bus.$emit('getLogin')
        }
      });
    },

    // 点击更换验证呢
    handleImgBarter() {
      this.getCaptchas();
    },

    // 点击查看验证码真假
    handleVerificationCode(username, password, captcha_code) {
      this.getLogin(username, password, captcha_code);
    },
  },
};
</script>
<style lang="less" scoped>
#login {
  position: relative;
  height: 100vh;
  background-color: #f5f5f5;
  z-index: 1;
}
</style>